module('waitingnet',package.seeall) 
require 'tcpnet'    
local tag_watingpad = 135010;
local m_seriaList={}; 
function clear()
  local layer=SceneManager:ins():getExitLayer()
  if layer then 
	layer:removeChildByTag(tag_watingpad, true); 
  end
  m_seriaList={}; 
end  
 
function waitingNetBegin(serianum,packetid)   
   table.insert(m_seriaList,serianum);
   print('发送了这么多个协议',#m_seriaList)
   print("可以加菊花吗") 
   local layer=SceneManager:ins():getExitLayer();
   if layer then 
		local pad = layer:getChildByTag(tag_watingpad); 
		if pad then 
			pad:setMessage('发送的协议号=' .. packetid)
			return;
		end
	end
   print("加菊花啦啦啦啦")   
   local waitingPad=WaitingDialog:showWaiting('正在通信中...','发送协议的菊花');
   waitingPad:setTag(tag_watingpad);
   waitingPad:setMessage('发送的协议号=' .. packetid);
   local function timeOut() 
		tcpnet.showNetError();
		print('菊花超时了')
    end
	performWithDelay(waitingPad ,timeOut,10)  
   local function eventfun(event) 
        if event == 'cleanup' or event == 'exit' then 
			m_seriaList={}; 
        end
    end   
	regNodeEvent(waitingPad,eventfun);  
end
function waitingNetEnd(serianum) 
   print("可以移除菊花吗")   
   for i=1,#m_seriaList do 
	if m_seriaList[i] == serianum then 
		table.remove(m_seriaList,i);
		break;
	end
   end
   if #m_seriaList<=0 then 
	--移除菊花 
    print("移除菊花啦啦啦啦")   
	clear();
   end
end





